package io.github.enbool.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.github.enbool.bean.ResultBean;
import io.github.enbool.bean.dto.UserRegisterDTO;
import io.github.enbool.bean.form.UserInforForm;
import io.github.enbool.domain.User;
import io.github.enbool.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/*
 * user api
 * @author enbool
 *
 */
@Api(description = "User管理接口")
@RestController
@RequestMapping
public class UserController { 		

	@Autowired
	private UserService userService;
	
	@ApiOperation(value = "注册帐号，帐号为禁用状态，需管理员先启用")
	@PostMapping("/users/register")
	public ResultBean<Boolean> register(@RequestBody UserRegisterDTO request) {
		
		return new ResultBean<>(userService.register(request));
	}
	
	/*@ApiOperation(value = "修改密码")
	@PutMapping(value = "/resetPassword")
	public ResultBean<Boolean> resetPassword(@RequestBody UserResetPasswordDTO request) {		
		
		return new ResultBean<>(userService.resetPassword(request));
	}*/
	
	@ApiOperation(value = "修改个人信息")
	@PutMapping(value = "/users/updateUserInfo")
	public ResultBean<Boolean> updateUserInfo(@RequestBody UserInforForm userInforForm) {		
		
		return new ResultBean<>(userService.updateUserInfo(userInforForm));
	}
	
	@ApiOperation(value = "Check if the user already existed in the system.")
	@ApiImplicitParam(name = "user", dataType = "string", value = "The identity of the user to check, maybe username, phone.", paramType = "query")
	@GetMapping("/users/existed")
	public ResultBean<Boolean> existed(@RequestParam String user) {
		
		return new ResultBean<>(userService.existed(user));
	}
	
	@ApiOperation(value = "获得当前用户的所有信息")
	@GetMapping("/users/me")
	public ResultBean<User> me() {
		
		return new ResultBean<>(userService.me());
	}
}